﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Diagnostics;
using bdxyit.com.RecruitmentAppSys.ViewModels;
using bdxyit.com.RecruitmentAppSys.Models;

namespace bdxyit.com.RecruitmentAppSys.Controllers
{
    public class WorkListInfoController : Controller
    {
        // GET: /WorkListInfo/

        public ActionResult Index(string id)
        {
            return View();
        }

        //
        // GET: /WorkListInfo/Details/5

        public ActionResult Details(string id)
        {
            //var workList = rDB.WorkListInfos.Where(a => a.UserID == id).ToList() ;

            //ViewBag.Users = id;

            //return View(workList);
            return View();
        }

        //
        // GET: /WorkListInfo/Create
        [HttpPost]
        public ActionResult Create(WorkListInfo wi)
        {
            //try
            //{
            //    rDB.WorkListInfos.Add(wi);
            //    rDB.SaveChanges();
            //    var mess = new OperatMessageViewModel();
            //    mess.Message = "添加工作履历成功";
            //    return  RedirectToAction("Index", "OperatMessage", new RouteValueDictionary(new
            //    {
            //          nextOperate = "WorkListInfo=CandidatePositions",
            //            mess = "添加工作履历成功",
            //          id = wi.UserID
            //    }));
            //}
            //catch
            //{
            //    return RedirectToAction("Index");
            //}
            return RedirectToAction("Index");
        } 

        //
        // POST: /WorkListInfo/Create

        public ActionResult Create(string id)
        {
            //var workList = new WorkListInfo();

            //workList.UserID = id.Split(',')[0];
            //if (id.Split(',').Length > 1) 
            //{
            //    var wl = rDB.WorkListInfos.Where(a => a.UserID == workList.UserID).ToList();
            //    if (wl != null) 
            //    {
            //        foreach (var w in wl) 
            //        {
            //            rDB.WorkListInfos.Remove(w);
            //        }
            //        rDB.SaveChanges();
            //    }
            //}
            //workList.StartTime = DateTime.Parse(DateTime.Now.ToShortDateString());
            //workList.EndTime = DateTime.Parse(DateTime.Now.ToShortDateString());

            return View();
        }
        
        //
        // GET: /WorkListInfo/Edit/5
 
        public ActionResult Edit(string id)
        {
            var workList = new WorkListInfo();

            workList.UserID = id;

            return View(workList);
        }

        //
        // POST: /WorkListInfo/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /WorkListInfo/Delete/5
 
        public ActionResult Delete(int id)
        {
            try
            {
                //var workList = rDB.WorkListInfos.Find(id);
                //rDB.WorkListInfos.Remove(workList);
                //rDB.SaveChanges();
                //return RedirectToAction("Details", "WorkListInfo", new
                //{
                //    ID = workList.UserID
                //});
            }
            catch
            {
                return RedirectToAction("Index");
            }
            return RedirectToAction("Index");
        }

        //
        // POST: /WorkListInfo/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            //try
            //{
            //    // TODO: Add delete logic here
            //    var del = rDB.WorkListInfos.Find(id);
            //    rDB.WorkListInfos.Remove(del);
            //    rDB.SaveChanges();
            //    return RedirectToAction("Details", "WorkListInfo", new
            //    {
            //        ID = del.UserID
            //    });
            //}
            //catch
            //{
            //    return RedirectToAction("Details");
            //}
            return RedirectToAction("Details");
        }
    }
}
